Skip to content

stats: auto-populate node.id and node.cluster in OTel stats sink resource#44066

Open
Retr0-XD wants to merge 4 commits intoenvoyproxy:mainfrom
Retr0-XD:feat/otel-stats-sink-node-resource-attrs-39931
Open

stats: auto-populate node.id and node.cluster in OTel stats sink resource#44066
Retr0-XD wants to merge 4 commits intoenvoyproxy:mainfrom
Retr0-XD:feat/otel-stats-sink-node-resource-attrs-39931

Conversation

@Retr0-XD
Copy link
Copy Markdown

@Retr0-XD Retr0-XD commented Mar 21, 2026

Problem

The OpenTelemetry stats sink emits metrics with an empty Resource (only telemetry.sdk.* attributes). Consumers such as OTel Collector processors have no way to identify which Envoy instance sent the metrics — making correlation of configs with metrics impossible.

Reported in #39931.

Solution

Automatically inject two resource attributes from LocalInfo when building the sink:

Attribute Source Example
node.id LocalInfo::nodeName() "envoy-pod-1"
node.cluster LocalInfo::clusterName() "my-service"

Priority rule: configured resource detectors take precedence — try_emplace ensures detector-set values are never overwritten.

Files changed

  • source/extensions/stat_sinks/open_telemetry/config.cc — inject node.id/node.cluster before constructing OtlpOptions
  • test/extensions/stats_sinks/open_telemetry/config_test.cc — factory smoke-test with non-empty node info + detector-priority test
  • test/extensions/stats_sinks/open_telemetry/open_telemetry_impl_test.cc — end-to-end flush test verifying attributes appear in ResourceMetrics

Example config

No config change required. With the existing bootstrap:

node:
  id: envoy-pod-1
  cluster: my-service
stats_sinks:
- name: envoy.stat_sinks.open_telemetry
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.stat_sinks.open_telemetry.v3.SinkConfig
    grpc_service:
      envoy_grpc:
        cluster_name: otel_collector

The exported ResourceMetrics.resource.attributes will now include:

node.id    = "envoy-pod-1"
node.cluster = "my-service"

AI disclosure: GitHub Copilot was used during implementation and test writing. I fully understand all changes made in this PR.

Commit Message: See PR title
Risk Level: Low
Testing: Unit tests added/verified
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A

@Retr0-XD Retr0-XD had a problem deploying to external-contributors March 21, 2026 09:57 — with GitHub Actions Error
@repokitteh-read-only
Copy link
Copy Markdown

Hi @Retr0-XD, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #44066 was opened by Retr0-XD.

see: more, trace.

…urce

The OpenTelemetry stats sink previously emitted metrics with an empty
Resource (or only telemetry.sdk.* attributes). Consumers downstream —
such as OTel Collector processors — had no way to identify which Envoy
instance emitted the metrics.

This change automatically injects `node.id` and `node.cluster` from
`LocalInfo` into the resource attributes of every export request.
Resource detectors configured by the user retain priority: if a
detector already sets those keys, the auto-populated values are skipped
(try_emplace semantics).

Fixes: envoyproxy#39931

Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com>
@Retr0-XD Retr0-XD force-pushed the feat/otel-stats-sink-node-resource-attrs-39931 branch from 59ecd90 to 6b784d5 Compare March 22, 2026 06:18
@Retr0-XD Retr0-XD requested a review from mattklein123 as a code owner March 22, 2026 06:18
@Retr0-XD Retr0-XD had a problem deploying to external-contributors March 22, 2026 06:18 — with GitHub Actions Error
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 25, 2026

@wbpcode wbpcode assigned kyessenov and unassigned kyessenov Mar 25, 2026
@Retr0-XD
Copy link
Copy Markdown
Author

@wbpcode can I get a review on this please :)

@kyessenov
Copy link
Copy Markdown
Contributor

I don't think we should be using node.id attribute, that's not standard with OTel semantic conventions and also inconsistent in general.

To set per-envoy attributes, you can already do it as follows:

  1. add environment resource detector to the sink, https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/tracers/opentelemetry/resource_detectors/v3/environment_resource_detector.proto#extensions-tracers-opentelemetry-resource-detectors-v3-environmentresourcedetectorconfig.
  2. add OTEL_RESOURCE_ATTRIBUTES=my.attribute=my_value with a baggage-encoded list of attributes.

@kyessenov
Copy link
Copy Markdown
Contributor

I'm putting a block because I think this would be a breaking change. The server-side in OTLP uses attribute presence for mapping and can be tripped off with a new default attribute.

Copy link
Copy Markdown
Contributor

@kyessenov kyessenov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Changed test expectations to use standard OTel semantic conventions:
- node.id → service.instance.id
- node.cluster → service.namespace

This aligns tests with the switch from custom attributes to standard
OTel conventions for Envoy instance identification.

Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com>
Changed implementation to use standard OpenTelemetry semantic conventions
instead of custom node attributes:
- node.id → service.instance.id (identifies the Envoy instance)
- node.cluster → service.namespace (provides cluster/namespace context)

This aligns with OTel standards and reduces risk of breaking changes
for server-side OTLP attribute processing logic.

Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com>
Updated test expectations to use standard OTel semantic conventions:
- node.id → service.instance.id
- node.cluster → service.namespace

Aligns with the switch from custom attributes to standard OTel
conventions for Envoy instance identification.

Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com>
@Retr0-XD Retr0-XD requested a deployment to external-contributors March 26, 2026 03:12 — with GitHub Actions Waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants